package com.zznzzn.myweb.service;

import com.zznzzn.myweb.exceptions.ServiceException;
import com.zznzzn.myweb.mapper.FavMapper;
import com.zznzzn.myweb.pojo.Favourite;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FavServiceImpl implements FavService {

    @Autowired
    private FavMapper favMapper;

    @Override
    public int addFav(Favourite favourite) {
        int re = favMapper.insertFav(favourite);
        if (re != 0){
            return re;
        }else{
            throw new ServiceException("创建收藏失败");
        }
    }

    @Override
    public int delFav(String itemid,String uuid) {
        int re = favMapper.deleteFav(itemid,uuid);
        if (re != 0){
            return re;
        }else{
            throw new ServiceException("删除收藏失败");
        }
    }

    @Override
    public List<Favourite> getFavByUser(String uuid) {
        return favMapper.queryFavByUuid(uuid);
    }
}
